$title Government model

$ontext
--------------------------------------------------------------------------------
Closed 2x2 economy with government collecting taxes.
Laurent Cretegny, CoPS, Monash University, Australia, 2003.
--------------------------------------------------------------------------------
$offtext

sets
  s                 commodity and sector          / agr, ind /
  f                 primary factor                / lab, cap /;

parameters
  sam(*,*)          benchmark social accounting matrix
  factor(f,s)       factor demand
  demand(s)         demand for consumption
  endow(f)          endowment
  govdem(s)         government demand
  tr_x(s)           tax revenue on consumption
  tr_y(s)           tax revenue on output
  supply(s)         supply of output
  cons              aggregate consumption
  govcons           aggregate government consumption
  t_x(s)            tax rate on consumption
  t_y(s)            tax rate on output
  t_x_l(s)          power of tax on consumption
  t_y_l(s)          power of tax on output;
  
$call gdxxrw i=govt.xls o=govt.gdx index=declare
$gdxin govt.gdx
$load sam = sam
$gdxin

factor(f,s) = sam(f,s);
demand(s) = sam(s,"ra");
endow(f) = sam("ra",f);
govdem(s) = sam(s,"gov");
tr_x("ind") = sam("tx","ra");
tr_y(s) = sam("ty",s);
supply(s) = sum(f, factor(f,s)) + tr_y(s);
cons = sum(s, demand(s) + tr_x(s));
govcons = sum(s, govdem(s));
t_x(s) = tr_x(s) / demand(s);
t_y(s) = tr_y(s) / supply(s);
t_x_l(s) = 1 + t_x(s);
t_y_l(s) = 1 - t_y(s);

$ontext
$model:govt

$sectors:
  y(s)              ! production
  c                 ! aggregate consumption
  g                 ! government expenditure

$commodities:
  p(s)              ! price of commodity
  pc                ! price of aggregate consumption
  pg                ! price of a unit of government output
  pf(f)             ! price of primary factor

$consumers:
  ra                ! representative agent income
  gov               ! government income

$prod:y(s)          s:1.0
  o:p(s)            q:supply(s)         p:t_y_l(s)          a:gov     t:t_y(s)
  i:pf(f)           q:factor(f,s)

$prod:c             s:1.0
  o:pc              q:cons
  i:p(s)            q:demand(s)         p:t_x_l(s)          a:gov     t:t_x(s)

$prod:g
  o:pg              q:govcons
  i:p(s)            q:govdem(s)

$demand:ra
  d:pc              q:cons
  e:pf(f)           q:endow(f)

$demand:gov
  d:pg              q:govcons

$report:
  v:r_cons(s)       i:p(s)              prod:c

$offtext
$sysinclude mpsgeset govt

* Benchmark replication

govt.iterlim = 0;
$include govt.gen
solve govt using mcp;
abort$(abs(govt.objval) gt 1e-8) "*** govt does not calibrate ! ***";
govt.iterlim = 1000;

* Fixation of a numeraire to allow comparison

ra.fx = ra.l;

* Counterfactual : 10% increase in tax rate on industrial output

t_x("ind") = t_x("ind") * 1.1;
t_y("ind") = t_y("ind") * 1.1;

$include govt.gen
solve govt using mcp;

* Results

parameters
  res_com           results by commodity in % change from basis
  res_agg           aggregate results in % change from basis; 

res_com("output",s) = (y.l(s) - 1) * 100;
res_com("cons",s) = (r_cons.l(s)/demand(s) - 1) * 100;
res_com("price",s) = (p.l(s) - 1) * 100;

res_agg("c") = (c.l - 1 ) * 100;
res_agg("pc") = (pc.l - 1 ) * 100;
res_agg("ra_inc") = (ra.l/cons - 1 ) * 100;

option decimals = 6;
display res_com, res_agg;

execute_unload 'sol_mps', y, c, g, p, pc, pg, pf, ra, gov, t_x, t_y;

* Check GEMPACK solution

govt.iterlim = 0;
$include gem2gdx
execute_load 'sol_gem', y, c, g, p, pc, pg, pf, ra, gov, t_x, t_y;

$include govt.gen
solve govt using mcp;
abort$(abs(govt.objval) gt 1e-5) "*** GEMPACK and GAMS solutions are different ! ***";
